/* in操作符收窄 */
type Fish = { swim: () => void };
type Bird = { fly: () => void };

function move(animal: Fish | Bird) {
  if ("swim" in animal) {
    return animal.swim();
    // (parameter) animal: Fish
  }

  return animal.fly();
  // (parameter) animal: Bird
}



type Fish1 = { swim: () => void };
type Bird1 = { fly: () => void };
type Human1 = { swim?: () => void; fly?: () => void };

function move1(animal: Fish1 | Bird1 | Human1) {
  if ("swim" in animal) {
    animal; // (parameter) animal: Fish | Human
  } else {
    animal; // (parameter) animal: Bird | Human
  }
}